package net.hnjdzy.tinydict.service;


import android.util.Log;

import com.alibaba.fastjson.JSON;

import net.hnjdzy.tinydict.entity.Word;


import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;



    public class WordManager {

        public Word getWordData(String word) throws Exception {
            OkHttpClient client = new OkHttpClient();
            String url = "http://dict-co.iciba.com/api/dictionary.php?w="+word+"&key=0A6FB8F9BECE36C1E10EB25283D1601A&type=json";
            Request request = new Request.Builder().url(url).build();
            Response response = client.newCall(request).execute();
            if (response.isSuccessful()) {
                String json = response.body().string();
                Log.d("test",json);
                return JSON.parseObject(json, Word.class);

            } else {
                Log.d("test", "网络连接错误");
                return null;
            }

        }
    }

